home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / begincpp.zip / #8.CPP < prev    next >
C/C++ Source or Header  |  1990-08-04  |  833b  |  55 lines

  1. // SRO.CXX  demonstrates the use of Scope Resolution Operator ::
  2.  
  3. #include <stream.hxx>
  4.  
  5. void proc1(), proc2();
  6.  
  7. int i = 1;    //global variable
  8.  
  9.  
  10. main()
  11. {
  12.     proc1();
  13.     proc2();
  14. }
  15.  
  16. void proc1()
  17. {
  18.     char c;
  19.  
  20.     class X {
  21.         char c;
  22.         class Y {
  23.             char d;
  24.             void foo (char e) { d = e; }
  25.         };
  26.         char goo (X *q) { return q->c; }
  27.     };
  28. }
  29.  
  30. void proc2()
  31. {
  32.     int i = 2;    //local variable
  33.  
  34.     {
  35.         int n = i;    //the i is the local i
  36.         int i = 3;    //hides the global and local i
  37.  
  38.         cout << "i = " << i << "\n";        //prints out  i = 3
  39.         cout << "::i = " << ::i << "\n";    //prints out  ::i = 1
  40.         cout << "n = " << n << "\n";        //prints out  n = 2
  41.  
  42.     }
  43.     cout << "i = " << i << "\n";            //prints out  i = 2
  44.     cout << "::i = " << ::i << "\n";        //prints out  ::i = 1
  45. }
  46.  
  47. /* output:
  48.  
  49. i = 3
  50. ::i = 1
  51. n = 2
  52. i = 2
  53. ::i = 1
  54.  
  55. */